//应收统计/导出

//财务明细单
interface IReceivableStatisticsViewModel_finance extends IBaseViewModel<IReceivableStatisticsFinanceQueryTerms>{
    /**
     * ui-grid控制
     */
    gridOptions: uiGrid.IGridOptionsOf<ReceivableSettleBillListItemResponse>;
    /**
     * 结算单位
     */
    settleName:string;
    /**
     * 起始时间
     */
    starttime:string;
    /**
     * 结束时间
     */
    endtime:string;
    /**
     * 返回事件
     */
    skipBack:()=> void;
    /**
     * 列表高
     */
    Fheight:number;
}

/**
 * 查询条件
 */
interface IReceivableStatisticsFinanceQueryTerms{

}

class IReceivableStatisticsExportController extends ListController<IReceivableStatisticsViewModel_finance,IReceivableStatisticsFinanceQueryTerms>{
    gridApi: uiGrid.IGridApiOf<ReceivableSettleBillListItemResponse>;

    orderBy: number = 0;
    asc:boolean = true;

    constructor($scope:IReceivableStatisticsViewModel_finance,private receivableService:IReceivableService,private $state: angular.ui.IStateService,
    private $location:ng.ILocationService,private exportService:IexportService,private $ngBootbox:BootboxService){
        super($scope);
        this.init();
    }

    init():void{
        super.init();        
        //结算单位
        this.$scope.settleName = this.$location.search().settle;
        //起始时间
        this.$scope.starttime = this.$location.search().starttime;
        //结束时间
        this.$scope.endtime = this.$location.search().endtime;

        this.$scope.gridOptions = {
            paginationPageSizes: [10, 20, 30],
            useExternalPagination: false,
            exporterMenuCsv: false,
            useExternalSorting: false,
            enableColumnResizing: true,
            exporterMenuPdf: false,
            enableGridMenu: true,
            columnDefs: [
                        { displayName: "应收总编号", field: 'billCode', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                        { displayName: "结算单位", field: 'settle', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                        { displayName: "应收总额", field: 'totalMoney', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                        { displayName: '结算员', field: 'reckoner', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                        { displayName: '开票状态', field: 'invoiceStatus', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                        { displayName: '开票日期', field: 'invoiceTime', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                        { displayName: '结算日期', field: 'creationTime', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
           ],
            onRegisterApi: (gridApi) => {
                this.gridApi = gridApi;
            }
        };

        this.loadData();
        this.$scope.skipBack = this.skipBack;

    }

    /**
     * 加载数据
     */
    loadData():void{
        this.receivableService.getreceivableSettleBillList("",null,"","",this.$scope.settleName,"",this.$scope.starttime,this.$scope.endtime,"","","","","","",0,-1).then((res)=>{
            this.$scope.gridOptions.data = res.data.data;
            this.$scope.Fheight = (10*39)+96;
        });
    }

    /**
     * 返回事件
     */
    skipBack=()=> {
        this.$state.go('app.receivable.receivable_census',{settle:this.$scope.settleName, starttime: this.$scope.starttime, endtime: this.$scope.endtime,name:'finance_excel' });
    }

    /**
     * 导出列表
     */
    exportFunc=()=>{
        var t=Number(window.localStorage.getItem('totalStatisticslist'));
        if(t>30000){
            this.$ngBootbox.alert('导出数据不可超过3万条');
            return
        }else{
            this.exportService.exportstatisticsreceivable(this.$scope.settleName,this.$scope.starttime,this.$scope.endtime);
        }
    }

}

angular.module("tms").controller("receivableStatisticsFinanceExcel",[ "$scope", "receivableService", "$state", "$location","exportService","$ngBootbox", IReceivableStatisticsExportController]);



//收入明细单
interface IReceivableStatisticsViewModel_incomeList extends IBaseViewModel<IReceivableStatisticsIncomeQueryTerms>{
    /**
     * ui-grid控制
     */
    gridOptions: uiGrid.IGridOptionsOf<IncomeListItemResponse>;
    /**
     * 结算单位
     */
    settleName:string;
    /**
     * 起始时间
     */
    starttime:string;
    /**
     * 结束时间
     */
    endtime:string;
    /**
     * 返回事件
     */
    skipBack:()=> void;
    /**
     * 列高
     */
    Iheight:number;
}

/**
 * 查询条件
 */
interface IReceivableStatisticsIncomeQueryTerms{

}

class IReceivableStatisticsIncomeListController extends ListController<IReceivableStatisticsViewModel_incomeList,IReceivableStatisticsIncomeQueryTerms> {
    gridApi: uiGrid.IGridApiOf<IncomeListItemResponse>;

    constructor($scope:IReceivableStatisticsViewModel_incomeList,private receivableService:IReceivableService,private $state: angular.ui.IStateService,
    private $location:ng.ILocationService,private exportService:IexportService){
        super($scope);
        this.init();
    }

    init():void{
        super.init();
        //结算单位
        this.$scope.settleName = this.$location.search().settle;
        //起始时间
        this.$scope.starttime = this.$location.search().starttime;
        //结束时间
        this.$scope.endtime = this.$location.search().endtime;

        this.$scope.gridOptions = {
            paginationPageSizes: [10, 20, 30],
            useExternalPagination: false,
            exporterMenuCsv: false,
            useExternalSorting: false,
            enableColumnResizing: true,
            exporterMenuPdf: false,
            enableGridMenu: true,
            columnDefs: [
                            { displayName: "收入编号", field: 'incomeCode', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: "结算单位", field: 'settle', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: "收入总额", field: 'amount', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '收入说明', field: 'description', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '收款日期', field: 'receiptTime', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
            ],
            onRegisterApi: (gridApi) => {
                this.gridApi = gridApi;
            }
        };

        this.loadData();
        this.$scope.skipBack = this.skipBack;
    }

    /**
     * 加载数据
     */
    loadData():void{
        this.receivableService.incomeList(this.$scope.settleName,this.$scope.starttime,this.$scope.endtime).then((res)=>{
            this.$scope.gridOptions.data = res.data.data;
            this.$scope.Iheight = (10 * 39)+ 96;
        })
    }

    /**
     * 返回事件
     */
    skipBack= ()=> {
        this.$state.go('app.receivable.receivable_census',{ settle:this.$scope.settleName, starttime:this.$scope.starttime, endtime:this.$scope.endtime,name:'income_excel' });
    }

    /**
     * 导出列表
     */
    exportFunc=()=>{
        this.exportService.exportstatisticsincome(this.$scope.settleName,this.$scope.starttime,this.$scope.endtime);
    }

}

angular.module("tms").controller("receivableStatisticsIncomeExcel",[ "$scope", "receivableService", "$state","$location","exportService", IReceivableStatisticsIncomeListController]);


//未结账明细单
interface IReceivableStatisticsViewModel_accountsList extends IBaseViewModel<IReceivableStatisticsAccountsQueryTerms>{
    /**
     * ui-grid控制
     */
    gridOptions: uiGrid.IGridOptionsOf<FinanceReceivableListItemResponse>;
    /**
     * 结算单位
     */
    settleName:string;
    /**
     * 起始时间
     */
    starttime:string;
    /**
     * 结束时间
     */
    endtime:string;
    /**
     * 结算状态集合
     */
    settleStatusList:string;
    /**
     * 返回事件
     */
    skipBack:()=> void;
    /**
     * 列高
     */
    Lheight:number;
}

/**
 * 查询条件
 */
interface IReceivableStatisticsAccountsQueryTerms{

}

class IReceivableStatisticsAccountsListController extends ListController<IReceivableStatisticsViewModel_accountsList,IReceivableStatisticsAccountsQueryTerms>{
    gridApi: uiGrid.IGridApiOf<FinanceReceivableListItemResponse>;

    constructor($scope:IReceivableStatisticsViewModel_accountsList,private receivableService:IReceivableService,private $state: angular.ui.IStateService,
    private $location:ng.ILocationService,private exportService:IexportService){
        super($scope);
        this.init();
    }

    init():void{
        super.init();
        //结算单位
        this.$scope.settleName = this.$location.search().settle;
        //起始时间
        this.$scope.starttime = this.$location.search().starttime;
        //结束时间
        this.$scope.endtime = this.$location.search().endtime;
        //结算状态集合
        this.$scope.settleStatusList = "1,2,3";

        this.$scope.gridOptions = {
            paginationPageSizes: [10, 20, 30],
            useExternalPagination: false,
            exporterMenuCsv: false,
            useExternalSorting: false,
            enableColumnResizing: true,
            exporterMenuPdf: false,
            enableGridMenu: true,
            columnDefs: [
                            { displayName: "应收编号", field: 'receivableCode', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: "应收费用类型", field: 'feeType', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: "应收说明", field: 'receivableSummary', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '客户单位', field: 'client', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '结算单位', field: 'settle', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '送货地址', field: 'originAddress', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '发货日期', field: 'realDeliveryTime', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '货物名称', field: 'goodsName', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '货物数量', field: 'quantityOfGoods', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '应收单价', field: 'receivablePrice', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '应收总价', field: 'receivableTotalPrice', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
                            { displayName: '合同号', field: 'contractNumber', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },
            ],
            onRegisterApi: (gridApi) => {
                this.gridApi = gridApi;
            }
        };

        this.loadData();
        this.$scope.skipBack = this.skipBack;

    }
    
    /**
     * 加载数据
     */
    loadData():void{
        this.receivableService.receivablelist("",null,"",this.$scope.settleName,"","",this.$scope.starttime,this.$scope.endtime,"",
        "","",this.$scope.settleStatusList ,"","","",null,"","",false,"","","","", "","",0,-1).then((res)=>{
            this.$scope.gridOptions.data = res.data.data;
            this.$scope.Lheight = (10 * 39)+96;
        });
        this.getListCount();
    }

    getListCount():void{
        this.receivableService.receivablecount("",this.$scope.settleName,"","",this.$scope.starttime,this.$scope.endtime,"",
        "","",this.$scope.settleStatusList ,"","","",null,"","",false,"","","","","","").then(res=>{
            this.$scope.gridOptions.totalItems = res.data.extData;
        })
    }

    /**
     * 返回事件
     */
    skipBack= ()=> {
        this.$state.go('app.receivable.receivable_census',{ settle:this.$scope.settleName, starttime:this.$scope.starttime, endtime:this.$scope.endtime,name:'arrearage_excel' });
    }

    /**
     * 导出列表
     */
    exportFunc=()=>{
        this.exportService.exportstatisticsaccount(this.$scope.settleName,this.$scope.starttime,this.$scope.endtime,this.$scope.settleStatusList);
    }

}

angular.module("tms").controller("receivableStatisticsAccountsExcel",[ "$scope", "receivableService", "$state", "$location","exportService",IReceivableStatisticsAccountsListController]);

